/**
 * 深拷贝、浅拷贝
 */

function deepClone(obj) {
    let deepObj = {}
    for (let objKey in obj) {
        if (obj[objKey] instanceof Object) {
            deepObj[objKey] = deepClone(obj[objKey])
        } else {
            deepObj[objKey] = obj[objKey]
        }
    }
    return deepObj
}

let student = {
    name: 'zhangsan',
    age: 18,
    sex: 'man',
    time: '1 mouth',
    sing: function () {
        console.log('sing')
    },
    deep: {
        dump: function () {
            console.log('dump')
        },
        time: '1 year',
        deep1: {
            arr: [1, 2, 3],
            time: '2 years old',
            rap: function () {
                console.log('rap')
            }
        }
    }
}

console.log('DeepStu:', deepClone(student))


// assign
let a = {}
let res = Object.assign(a, student)
student.deep.time = 'iKun'      //第一层是深拷贝，但是再深入是浅拷贝
console.log('res', res)

// JSON序列化 反序列化
console.log('JSON', JSON.parse(JSON.stringify(student)))   //拷贝不了函数



